#include <iostream>
#include <vector>
using namespace std;
const int N=40;

int a[N],b[N];
int n;
vector<int> ret;
void dfs(int start,int left,int right)
{
	if(start<1 || start>n)
		return ;
	if(right<left)
		return;
//	cout<<a[start]<<endl;
	ret.push_back(a[start]);
	int pos=left;
	
	while(pos<=right && b[pos]!=a[start])
	{
		pos++;
	}
	
	dfs(start-(right-pos+1),left,pos-1);
	
	dfs(start-1,pos+1,right);
}
int main()
{
	
	
	cin>>n;
	
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
		
	dfs(n,1,n);
	for(int i=0;i<ret.size();i++)
		cout<<ret[i]<<' ';
	return 0;
}
//6
//3 4 2 6 5 1
//3 2 4 1 6 5
